﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DiveManager
{
    public partial class SupplierHistory : Form
    {
        public string id_weitergabe;
        public string id_search;

        protected DiveDatabaseEntities diveDatabase;
        protected BindingSource bindingSource;
        
        
        public SupplierHistory()
        {
            InitializeComponent();

            // Init Database
            diveDatabase = new DiveDatabaseEntities();
            bindingSource = new BindingSource();
        }

        private void SupplierHistory_Load(object sender, EventArgs e)
        {
            //Übernahme der GUID aus der normalen Lieferantenanzeige
            this.id_search = Weitergabe_Details;

            LoadData();

            txID.DataBindings.Add(new Binding("Text", bindingSource, "ID"));
        }
        protected void LoadData()
        {

            Guid id_guid = new Guid(id_search);
            IQueryable<Supplier_History> dataQuery = from sh in diveDatabase.Supplier_History
                                                     where sh.Supplier_ID == id_guid
                                                     select sh;

            // Bind Data to BindingSource
            bindingSource.DataSource = dataQuery;

            // Bind BindingSource to List
            HistoryList.DataSource = bindingSource;


            // Hide ID-Columns
            HistoryList.Columns["ID"].Visible = false;
            HistoryList.Columns["Supplier_ID"].Visible = false;
            HistoryList.Columns["Changes"].Visible = true;
            HistoryList.Columns["User"].Visible = true;


            // Set Column Headers
            HistoryList.Columns["Changes"].HeaderText = "Änderungen";
            HistoryList.Columns["User"].HeaderText = "Geändert durch";


        }
        public string Weitergabe_Details
        {
            get;
            set;
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btDetails_Click(object sender, EventArgs e)
        {
            //In den TextBoxen angezeigter Lieferant an SupplierDetails Form
            //übergeben und dort den Lieferanten im Detail anzeigen,
            //wenn entsprechende Rechte vorhanden
            this.txID.Visible = true;
            id_weitergabe = txID.Text;
            this.txID.Visible = false;
            SupplierHistoryListed suphislist = new SupplierHistoryListed();
            suphislist.Weitergabe_Details = id_weitergabe;
            suphislist.Show();
        }
    }
}
